import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterlib/common/config/config.dart';
import 'package:flutterlib/common/style/font_awesome4_icons.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/navigator_utils.dart';
import 'package:flutterlib/model/post/post_bean.dart';
import 'package:flutterlib/widgets/bussiness/user_info_widget.dart';
import 'package:like_button/like_button.dart';

abstract class BasePostListItem extends StatelessWidget {
  final PostBean postBean;

  final VoidCallback onPressed;


  BasePostListItem(this.postBean,
      {this.onPressed,
        })
      : super();


  @override
  Widget build(BuildContext context);

  // @override
  // Widget build(BuildContext context) {
  //   if (postBean != null && (postBean.thumbnail ?? '').isNotEmpty) {
  //     return normalItem(context);
  //   } else {
  //     return simpleItem(context);
  //   }
  // }

  Widget simpleItem(BuildContext context) => Padding(
    padding: const EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 8),
    child: InkWell(
      splashColor: Colors.transparent,
      onTap: () {
        onPressed();
      },
      child: Container(
        decoration: BoxDecoration(
          borderRadius: const BorderRadius.all(Radius.circular(10.0)),
          boxShadow: <BoxShadow>[
            BoxShadow(
              color: Colors.grey.withOpacity(0.6),
              offset: const Offset(4, 4),
              blurRadius: 16,
            ),
          ],
        ),
        child: ClipRRect(
          borderRadius: const BorderRadius.all(Radius.circular(10.0)),
          child: Container(
            color: QuhuiColors.white,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Expanded(
                  child: Container(
                    child: Padding(
                      padding: const EdgeInsets.only(
                          left: 16, top: 8, bottom: 0),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Row(
                            children: [
                              Expanded(
                                child: Text(postBean.title,
                                    textAlign: TextAlign.left,
                                    style: QuhuiConstant.smallTextBold),
                              ),
                            ],
                          ),
                          Row(
                            children: [
                              UserInfoWidget(
                                width: 33,
                                height: 33,
                                image: postBean.userLogo,
                                onPressed: () {
                                  NavigatorUtils.goUserHome(
                                      context, postBean.userId);
                                },
                              ),
                              Text(
                                postBean.userName,
                                style: QuhuiConstant.smallSubText,
                              ),
                            ],
                          ),
                          Padding(
                            padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: <Widget>[
                                Expanded(
                                  child: Text(
                                    postBean.summary,
                                    overflow: TextOverflow.ellipsis,
                                    style: QuhuiConstant.minSubText,
                                  ),
                                ),
                              ],
                            ),
                          ),
                          buildOperation(),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  );

  Widget normalItem(BuildContext context) => Padding(
    padding: const EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 8),
    child: InkWell(
      splashColor: Colors.transparent,
      onTap: () {
        onPressed();
      },
      child: Container(
        decoration: BoxDecoration(
          borderRadius: const BorderRadius.all(Radius.circular(10.0)),
          boxShadow: <BoxShadow>[
            BoxShadow(
              color: Colors.grey.withOpacity(0.6),
              offset: const Offset(4, 4),
              blurRadius: 16,
            ),
          ],
        ),
        child: ClipRRect(
          borderRadius: const BorderRadius.all(Radius.circular(10.0)),
          child: Column(
            children: <Widget>[
              AspectRatio(
                aspectRatio: 2,
                child: Stack(
                  fit: StackFit.expand,
                  children: [
                    ExtendedImage.network(
                      postBean.thumbnail,
                      fit: BoxFit.cover,
                    ),
                    Positioned(
                      left: 10,
                      top: 10,
                      child: Row(
                        children: [
                          UserInfoWidget(
                            width: 33,
                            height: 33,
                            image: postBean.userLogo,
                            onPressed: () {
                              NavigatorUtils.goUserHome(
                                  context, postBean.userId);
                            },
                          ),
                          Text(
                            postBean.userName,
                            style: QuhuiConstant.smallTextWhite,
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                color: QuhuiColors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        child: Padding(
                          padding: const EdgeInsets.only(
                              left: 16, top: 8, bottom: 0),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: [
                                  Expanded(
                                    child: Text(postBean.title,
                                        textAlign: TextAlign.left,
                                        style: QuhuiConstant.smallTextBold),
                                  ),
                                  Padding(
                                    padding:
                                    const EdgeInsets.only(right: 8.0),
                                    child: Text(
                                      "浏览 ${postBean.visits}",
                                      style: QuhuiConstant.smallSubText,
                                    ),
                                  )
                                ],
                              ),
                              Padding(
                                padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                                child: Row(
                                  crossAxisAlignment:
                                  CrossAxisAlignment.center,
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: <Widget>[
                                    Expanded(
                                      child: Text(
                                        postBean.summary,
                                        overflow: TextOverflow.ellipsis,
                                        style: QuhuiConstant.minSubText,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              buildOperation(),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    ),
  );

  buildOperation();


}
